<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-01-06 13:47:30
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-08-08 10:17:53
 * @FilePath: \mould\src\views\pages\Supervision\deliverability.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" id="buttonId" style="width: 100%">
          <vDatePicker
            type="date"
            :option="1"
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="130px !important"
          >
          </vDatePicker>
          <el-time-select
            class="timeNum"
            @change="yj_searchForm(getList)"
            placeholder="起始时间"
            v-model="startTime"
            :picker-options="{
              start: '00:00',
              step: '01:00',
              end: '23:00',
            }"
          >
          </el-time-select>
          <el-time-select
            class="timeNum"
            @change="yj_searchForm(getList)"
            placeholder="结束时间"
            v-model="endTime"
            :picker-options="{
              start: '00:00',
              step: '01:00',
              end: '23:00',
              minTime: startTime,
            }"
          >
          </el-time-select>
          <el-select
            class="selectCondition"
            v-model="getList.fConstructionhorizon"
            placeholder="施工层位"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in sgcDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.fMixturetype"
            placeholder="沥青混合料类型"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in liqhDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhz"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectBhz"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <div class="" style="width: 100%; height: 100%">
        <myCharts
          v-loading="chartsLoading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.3)"
          :time1="this.value2[0]"
          :time2="this.value2[1]"
          :commonData="tableData"
          :xData="xAllData"
        >
        </myCharts>
      </div>
      <div class="text_table"></div>
    </div>
  </div>
</template>
  
<script>
import vDatePicker from "@/components/public/v-DatePicker";
// import tree from "@/components/public/pitchManage_tree"; //左侧机构树
import tree from "@/components/stationProductionPage/pitchManage/tree"; //左侧机构树
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import myCharts from "@/components/stationProductionPage/pitchManage/dataAnalysisManage/productionPeriodCharts";

// import formJs from './regexDetail.js'//新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  // getCensusList2,//查询-产能分析列表页
  getStationmachineList, //拌合站列表
  getMachineListByStationId, //获取拌合机
  //  沥青拌合站数据分析生产时段分析
  getProductionTimeList,
  getAsphaltRecipeListByCompanyId, // 查询-沥青混合料类型下拉框
} from "@/api/request.js";
import formJs from "./regexDetail.js"; //新增弹框配置项

export default {
  name: "productionPeriod",
  data() {
    return {
      name: "productionPeriod", //按钮配置页面代号
      yj_view: null, //查看按钮是否显示
      formData: {}, //新增编辑向后台传递对象
      sgcDataList: formJs.sgcDataList, //施工层位
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机
      liqhDataList: [], //沥青混合料类型
      startTime: "00:00",
      endTime: "23:00",
      value2: "", //主页面日期筛选绑定值
      // 列表配置项
      tableData: [], //表格列表数据列表
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", //拌合站
        machineId: "", //拌合机
        fConstructionhorizon: "", // 施工层位
        fMixturetype: "", //  沥青混合料类型
        warningLevel: "", // 预警等级
        fCloseoperation: "", //闭合状态
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
      },
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },

      chartsLoading: true,
      xAllData: [],
    };
  },
  components: {
    tree, //左侧组织机构数
    vDatePicker,
    elBreadcrumb, //面包屑

    myCharts,
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));

    if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"))) {
      var data = JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"));
      this.getList.fCompanyid = data.fCompanyid; // 施工标段id
      // this.getList.startDates = data.startDates; // 开始时间
      // this.getList.endDates = data.endDates; // 截至时间
      this.getList.fConstructionhorizon = data.fConstructionhorizon; // 施工层位
      this.getList.fMixturetype = data.fMixturetype; //  沥青混合料类型
      this.getList.stationId = data.stationId;
      this.getList.machineId = data.machineId;
      this.getbhjDataMethods(this.getList.stationId);
    }

    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },

  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_view = true;
      }
    },

    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "3", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
              this.mixingPlantList(0, {
                fCompanyid: this.treeData[0].fCompanyid,
              });
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-pitchManage_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid);

            this.mixingPlantList(0, this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    handleNodeClick(data) {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");

      this.showName = data.fShortname; //顶部显示机构名
      if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("yjSmart-pitchManage_getLists")
        );
        this.getList.fCompanyid = data.fCompanyid;
        // this.value2 = `${y}-${m}-${d}`;
      } else {
        this.getList.fCompanyid = data.fCompanyid;
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fConstructionhorizon = ""; // 施工层位
        this.getList.fMixturetype = ""; //  沥青混合料类型
        this.getList.warningLevel = ""; // 预警等级
        this.getList.fCloseoperation = ""; // 闭合状态
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
      this.value2 = `${y}-${m}-${d}`;

      this.getList.stationId = "";
      this.getList.machineId = "";
      this.getList.page = 1;
      this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid);

      this.mixingPlantList(0, this.getList);
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      this.chartsLoading = true;
      console.log(this.startTime.slice(0, 2));
      window.sessionStorage.setItem(
        "yjSmart-pitchManage_getLists",
        JSON.stringify(data)
      );
      var datas = {
        fCompanyid: data.fCompanyid, // 施工标段id
        startDates: this.startTime.slice(0, 2), // 开始时间
        endDates: this.endTime.slice(0, 2), // 截至时间
        timeStr: this.value2, // 日期时间
        stationId: data.stationId, // 拌合站id
        machineId: data.machineId, // 拌合机id
        fConstructionhorizon: data.fConstructionhorizon, // 施工层位
        fMixturetype: data.fMixturetype, //  沥青混合料类型
      };
      if (data.machineId != "") {
        let params = {
          machineId: data.machineId,
        };
        this.$store.dispatch("getLqCommonData/getLqCommonData", params);
        var that = this;
        setTimeout(() => {
          var xData = JSON.parse(
            JSON.stringify(this.$store.state.getLqCommonData.dataList)
          );
          that.xAllData = [
            "总产量",
            "矿粉",
            xData.fParm1,
            xData.fParm2,
            xData.fParm3,
            xData.fParm4,
            xData.fParm5,
            xData.fParm6,
            "沥青",
          ];
        }, 500);
        getProductionTimeList(datas)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.listLoading = false;
              this.chartsLoading = false;
              that.tableData = res.data.productionTimeList;
            } else {
              this.$message.error(res.msg);
              this.chartsLoading = false;

              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      } else {
        this.xAllData = [
          "总产量",
          "矿粉",
          "1#仓碎石",
          "2#仓碎石",
          "3#仓碎石",
          "4#仓碎石",
          "5#仓碎石",
          "6#仓碎石",
          "沥青",
        ];
        getProductionTimeList(datas)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.listLoading = false;
              this.chartsLoading = false;
              that.tableData = res.data.productionTimeList;
            } else {
              this.$message.error(res.msg);
              this.chartsLoading = false;

              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
    },
    getAsphaltRecipeListByCompanyId(id) {
      var data = {
        fCompanyid: id,
      };
      this.liqhDataList = [];
      getAsphaltRecipeListByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.asphaltRecipeList;
            this.liqhDataList = [
              {
                fItemName: "所有沥青混合料类型",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.liqhDataList.push({
                fItemName: item.fMixturetype,
                fItemValue: item.fMixturetype,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "3", // 拌合站类型
      };

      this.bhzDataList = [];
      this.bhjDataList = [];
      getStationmachineList(data)
        .then((res) => {
          console.log(8787, res);
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            if (num == 0) {
              this.bhzDataList = [
                {
                  fItemName: "所有拌和站",
                  fItemValue: "",
                },
              ];
              arr.map((item) => {
                this.bhzDataList.push({
                  fItemName: item.fMachinename,
                  fItemValue: item.fMachineid,
                });
              });
            }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    selectBhz(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
    },
    // 获取拌合机
    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 时间间隔
    selectTime(e) {
      // console.log(e);
      this.value2 = e;
      // this.getList.startDates = this.value2[0] // 开始时间
      // this.getList.endDates = this.value2[1] // 截至时间
      // this.xlsxName = this.value2[0] + '至' + this.value2[1] + '混凝土拌和站记录数据'

      this.yj_searchForm(this.getList);
    },

    getDate() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      var times = `${y}-${m}-${d}`;
      if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("yjSmart-pitchManage_getLists")
        );
        this.getList.page = 1;
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间

        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
      }
      this.value2 = times;
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialCharts {
  height: calc(100% - 110px);
  width: 100%;
}

/* .selectcheckbox {
    margin-left: 15px;
    margin-top: -5px;
    height: 35px;
} */
.timeNum /deep/ .el-input__inner {
  width: 70px !important;
}

.mechanism_nav_left .timeNum {
  width: 70px !important;
  min-width: 70px !important;
  margin-right: 8px;
}

.timeNum /deep/ .el-icon-time:before {
  display: none;
}
</style>